package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.bean.OrderDetail;
import com.itheima.bean.Orders;
import com.itheima.common.R;
import com.itheima.dto.OrdersDto;
import com.itheima.exception.CustomException;
import com.itheima.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RequestMapping("/order")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    //用户下单
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        //1.调用service处理
        orderService.submit(orders);

        //2.响应数据 "下单成功"
        return R.success("下单成功！");
    }

    @GetMapping("/page")
    public R<Page<Orders>> findPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer pageSize,
                                    String number, String beginTime, String endTime){

        Page<Orders> ordersList = orderService.findPage(page, pageSize,number,beginTime,endTime);
        return R.success(ordersList);
    }

    @GetMapping("/userPage")
    public R<Page<OrdersDto>> findUserPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1")Integer pageSize){

        Page<OrdersDto> ordersList = orderService.findUserPage(page,pageSize);

        return R.success(ordersList);
    }

    @PutMapping
    public R<String> deleteOrder(@RequestBody Orders orders){
        orderService.updateById(orders);
        return R.success("状态更改成功！！！");
    }
}
